﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.CountyFireManagement.Api.Models;
using ChuanYe.CountyFireManagement.EF.MySQL.Models;
using ChuanYe.CountyFireManagement.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.CountyFireManagement.Api.Controllers
{
    /// <summary>
    /// 火灾记录坐标记录
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FireLocationRecordController : ControllerBase
    {
        /// <summary>
        ///  增加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> Add(FireLocationRecordArrayRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                List<Firelocationrecord>  infos = new List<Firelocationrecord>();
                foreach (var item in obj.LocationRecords)
                {
                    Firelocationrecord info = new Firelocationrecord();
                    info.FireId = item.FireId;
                    info.Imei = item.Imei;
                    info.LocationRecordId = item.LocationRecordId;
                    info.Accuracy = item.Accuracy;
                    info.Latitude = item.Latitude;
                    info.Longitude = item.Longitude;
                    info.RealName = item.RealName;
                    info.UserId = item.UserId;
                    info.TransDatetime = item.TransDatetime;
                    info.RecordType = item.RecordType;
                    infos.Add(info);
                }
                result.FirstParam = BLL.FireLocationRecordBLL.Instance.Add(infos);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/FireLocationRecord/Add Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<Firelocationrecord>> Get(FireLocationRecordSearchRequest obj)
        {
            ResultDto<List<Firelocationrecord>> result = new ResultDto<List<Firelocationrecord>>();
            try
            {
               result.FirstParam= BLL.FireLocationRecordBLL.Instance.Get(obj.FireId,obj.RecordType);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/FireLocationRecord/Get Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }
    }
}